package com.xnyzc.lhy.order.service.impl.system;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xnyzc.lhy.common.constant.MessageConstant;
import com.xnyzc.lhy.common.entity.Qw;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.order.entity.system.OaSysUser;
import com.xnyzc.lhy.order.entity.vehicle.OaSysUserHand;
import com.xnyzc.lhy.order.mapper.system.OaSysUserMapper;
import com.xnyzc.lhy.order.mapper.vehicle.OaSysUserHandMapper;
import com.xnyzc.lhy.order.service.system.IOaSysUserHandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理员处理事项记录表 服务实现类
 * </p>
 *
 * @author lhy@xnyzc.com
 * @since 2019-07-24
 */
@Service
public class OaSysUserHandServiceImpl extends ServiceImpl<OaSysUserHandMapper, OaSysUserHand> implements IOaSysUserHandService {

    @Autowired
    private OaSysUserHandMapper handMapper;

    @Autowired
    private OaSysUserMapper userMapper;

    /**
     * 查询今日处理事项
     *
     * @param userId 管理员ID
     * @param type   查询类型
     * @param vehNo  车牌号
     */
    @Override
    public Rv todayHandler(String userId, Integer type, String vehNo) {
        OaSysUser oaSysUser = userMapper.selectById(userId);
        if (null == oaSysUser) {
            return Rv.wrap(EErrorCode.argCheckErr, MessageConstant.USER_ID_ERROR);
        }

        Qw qw = Qw.create();
        qw.eq("sys_user_id", oaSysUser.getSysUserId());

        if (null != vehNo && !vehNo.equals("")) {
            qw.eq("veh_no", vehNo);
        }

        //默认全部类型查询
        if (type != -1) {
            qw.eq("hand_matters", type);
        }

        return Rv.wrap(EErrorCode.success, handMapper.selectList(qw));
    }
}
